import { GridViewActionType, IGridViewAbility, IParam } from '@/core/interface';
import { IGridViewController } from '@/core/interface/view/controller';
import { IGridViewStore } from '@/core/interface/view/store';
import { IGridAbility } from '@/core/interface/widgets/ability';
import { MDViewController } from './md-view-controller';

/**
 * 表格视图控制器
 *
 * @export
 * @class GridViewController
 * @extends {ViewController}
 */
export class GridViewController
	extends MDViewController<GridViewActionType, IGridViewStore, IGridViewAbility>
	implements IGridViewController<IGridViewStore, IGridViewAbility>
{
	/**
	 * 获取表格部件能力
	 *
	 * @protected
	 * @return {*}  {(IGridAbility | undefined)}
	 * @memberof GridViewController
	 */
	protected getMainCtrlAbility(): IGridAbility | undefined {
		const grid = this.model.ctrls.find(
			(ctrl: IParam) => ctrl.controlType === 'GRID'
		);
		if (grid) {
			return this.getSubAbility<IGridAbility>(grid.name);
		}
		return undefined;
	}
}
